<?php

namespace App\Http\Middleware;

use Closure;

use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;

class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

public function handle($request, Closure $next)
{
// 注册后发邮件
  $rs = $next($request);
//$request->user()->email;
if($request->user()) {
    $mail = new Message;
    #注意,下行的setFrom要和你的邮箱名保持一致
    $mail->setFrom('admins <18064163469@163.com>')
    ->addTo($request->user()->email)
    ->setSubject('试试我的中间件')
    ->setBody("真好用!");

    $mailer = new SmtpMailer(array(
    'host' => 'smtp.163.com',
    'username' => '18064163469',#你的163用户名
    'password' => 'qwe123520'# 你的邮箱密码
    ));
    $mailer->send($mail);
    }
    return $rs;
}

}
